﻿using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Phone.Controls;

namespace MobiSms.UX
{
    public class UXPathButtonWithParam : Button
    {
        public UXPathButtonWithParam()
        {
            DefaultStyleKey = typeof(UXPathButtonWithParam);
            Click += new RoutedEventHandler(UXPathButton_Click);
        }

        void UXPathButton_Click(object sender, RoutedEventArgs e)
        {
            if (Uri != null)
            {
                Uri = new System.Uri(string.Format("{0}?{1}={2}", Uri, ParameterName, ParameterValue), UriKind.RelativeOrAbsolute);

                PhoneApplicationFrame frame = (PhoneApplicationFrame)Application.Current.RootVisual;
                frame.Navigate(Uri);
            }
        }

        #region IconPath
        public string IconPath
        {
            get { return GetValue(IconPathProperty) as string; }
            set { SetValue(IconPathProperty, value); }
        }

        public static readonly DependencyProperty IconPathProperty = DependencyProperty.Register(
            "IconPath",
            typeof(String),
            typeof(UXPathButtonWithParam),
            new PropertyMetadata(null));
        #endregion

        #region Uri
        public Uri Uri
        {
            get { return GetValue(UriProperty) as Uri; }
            set { SetValue(UriProperty, value); }
        }

        public static readonly DependencyProperty UriProperty = DependencyProperty.Register(
            "Uri",
            typeof(Uri),
            typeof(UXPathButtonWithParam),
            new PropertyMetadata(null)); 
        #endregion

        #region ParameterName
        [Category("Common Properties")]
        public string ParameterName
        {
            get { return GetValue(ParameterNameProperty) as string; }
            set { SetValue(ParameterNameProperty, value); }
        }

        public static readonly DependencyProperty ParameterNameProperty = DependencyProperty.Register(
            "ParameterName",
            typeof(string),
            typeof(UXPathButtonWithParam),
            new PropertyMetadata(null));
        #endregion

        #region ParameterValue
        [Category("Common Properties")]
        public string ParameterValue
        {
            get { return GetValue(ParameterValueProperty) as string; }
            set { SetValue(ParameterValueProperty, value); }
        }

        public static readonly DependencyProperty ParameterValueProperty = DependencyProperty.Register(
            "ParameterValue",
            typeof(string),
            typeof(UXPathButtonWithParam),
            new PropertyMetadata(null));
        #endregion

        #region Angle
        public double Angle
        {
            get { return (double)GetValue(AngleProperty); }
            set
            {
                SetValue(AngleProperty, value);
            }
        }

        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register(
            "Angle",
            typeof(double),
            typeof(UXPathButtonWithParam),
            new PropertyMetadata(0.00)); 
        #endregion

        #region StrokeThickness
        public double StrokeThickness
        {
            get { return (double)GetValue(StrokeThicknessProperty); }
            set
            {
                SetValue(StrokeThicknessProperty, value);
            }
        }

        public static readonly DependencyProperty StrokeThicknessProperty = DependencyProperty.Register(
            "StrokeThickness",
            typeof(double),
            typeof(UXPathButtonWithParam),
            new PropertyMetadata(3.00));
        #endregion
    }


}
